<%@ include file="/WEB-INF/jsp/include.jsp"%>
<%@ include file="/WEB-INF/jsp/editionFeatures.jsp"%>

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<title><c:out value="${hostname}" />: Entuity Ltd.</title>

<!--Make sure we make this test as the first thing. We don;t want to load other javascript files into
       document causing error message displayed in console
   -->


<jsp:include page="webstartDetect.jsp" />
<%@ include file="/WEB-INF/jsp/standardIncludes.jspf"%>

<!--  TODO: move these to standard includes ??? -->
<link rel="stylesheet" type="text/css" 	href="/webUI/yui/build/reset-fonts-grids/reset-fonts-grids.css" />
<link rel="stylesheet" type="text/css" 	href="/webUI/yui/build/resize/assets/skins/sam/resize.css" />
<link rel="stylesheet" type="text/css" 	href="/webUI/yui/build/layout/assets/skins/sam/layout.css" />
<link rel="stylesheet" type="text/css" 	href="/webUI/yui/build/button/assets/skins/sam/button.css" />
<link rel="stylesheet" type="text/css" 	href="/webUI/yui/build/container/assets/container-core.css" />
<script type="text/javascript" src="/webUI/yui/build/event/event-min.js"></script>
<script type="text/javascript" src="/webUI/yui/build/dom/dom-min.js"></script>

<script type="text/javascript" 	src="/webUI/yui/build/element/element-min.js"></script>
<script type="text/javascript" 	src="/webUI/yui/build/dragdrop/dragdrop-min.js"></script>
<script type="text/javascript" 	src="/webUI/yui/build/resize/resize-min.js"></script>
<script type="text/javascript" 	src="/webUI/yui/build/animation/animation-min.js"></script>
<script type="text/javascript" 	src="/webUI/yui/build/layout/layout-min.js"></script>
<script type="text/javascript" 	src="/webUI/yui/build/container/container-min.js"></script>
<script type="text/javascript" 	src="/webUI/yui/build/connection/connection-min.js"></script>

<script type='text/javascript' src='/webUI/dwr/interface/flowHelper.js'></script>
<script type='text/javascript' 	src='/webUI/dwr/interface/extendedMenuHelper.js'></script>
<script type='text/javascript' 	src='/webUI/dwr/interface/viewManagementHelper.js'></script>
<script type='text/javascript' 	src='/webUI/dwr/interface/globalAccessHelper.js'></script>
<script type='text/javascript' 	src='/webUI/dwr/interface/inventoryHelper.js'></script>

<!-- YUI IFrame fix -->
<script type="text/javascript" src="/webUI/js/yuiUtils.js"></script>
<script type="text/javascript" src="/webUI/js/dateTimeControl.js"></script>
<script type="text/javascript" src="/webUI/js/eventSuppress.js"></script>
<script type="text/javascript" src="/webUI/js/flowInventoryConfig.js"></script>

<!-- Entuity's tree implementation -->
<script type="text/javascript" src="/webUI/js/tree.js"></script>
<script type='text/javascript' src='/webUI/js/dataTable.js'></script>

<!-- Inventory classes -->
<script type="text/javascript" src="/webUI/js/inventory.js"></script>
<script type="text/javascript" 	src="/webUI/js/inventory_autoDiscovery.js"></script>
<script type="text/javascript" 	src="/webUI/js/inventory_candidateDevices.js"></script>

<!-- View Management -->
<script type="text/javascript" src="/webUI/js/viewManagement.js"></script>
<script type="text/javascript" src="/webUI/js/viewFilterManagement.js"></script>

<!-- Live Object status -->
<script type="text/javascript" src="/webUI/js/liveObjectStatus.js"></script>

<!-- Global Drag and Drop -->
<script type="text/javascript" src="/webUI/js/globalDragDrop.js"></script>

<!-- Custom dashboard editor -->
<script type="text/javascript" src="/webUI/js/customDashboard.js"></script>
<script type="text/javascript" src="/webUI/dwr/interface/customDashboardHelper.js"></script>

<script type="text/javascript" src="/webUI/js/userSelections.js"></script>
<script type="text/javascript" src="/webUI/dwr/interface/userSelectionHelper.js"></script>

<!-- Active chart helpers -->
<script type='text/javascript' src='/webUI/dwr/interface/objectDetailsHelper.js'></script>
<script type='text/javascript' src='/webUI/js/objectDetails.js'></script>


<!-- TODO: review this script and put it in a library -->
<script type="text/javascript">


(function()
  {
    var Dom = YAHOO.util.Dom;
    var Event = YAHOO.util.Event;

    function doTreeClicked()
    {
        var div = document.getElementById ("userSelectionDiv");
        if (div)
        {
            YAHOO.util.Dom.addClass (div, "hidden_item"); 
        }

        div = document.getElementById ("browseControlls");
        if (div)
        {
            YAHOO.util.Dom.removeClass (div, "hidden_item"); 
        }

        div = document.getElementById ("userSelectionControlls");
        if (div)
        {
            YAHOO.util.Dom.addClass (div, "hidden_item"); 
        }
        
    	div = document.getElementById ("selectorDiv");
    	if (div)
    	{
    		YAHOO.util.Dom.removeClass (div, "hidden_item"); 
    	}

    	 var unit = EYE.Globals.layout.getUnitByPosition('left');
    	 if (unit)
    		unit.resize(true); 
    }

    function doSelectionClicked()
    {
        var div = document.getElementById ("selectorDiv");
        if (div)
        {
            YAHOO.util.Dom.addClass (div, "hidden_item"); 
        }
        
        div = document.getElementById ("userSelectionDiv");
        if (div)
        {
            YAHOO.util.Dom.removeClass (div, "hidden_item"); 
        }

        div = document.getElementById ("browseControlls");
        if (div)
        {
            YAHOO.util.Dom.addClass (div, "hidden_item"); 
        }

        div = document.getElementById ("userSelectionControlls");
        if (div)
        {
            YAHOO.util.Dom.removeClass (div, "hidden_item"); 
        }

        var unit = EYE.Globals.layout.getUnitByPosition('left');
        if (unit)
            unit.resize(true);

        var width  = unit.getSizes().body.w;
        var height = unit.getSizes().body.h;
        
        EYE.Globals.userSelections.resize(width, height);
    }


    function setPinnedSelector(pinned)
    {
		if (pinned)
		{
		    EYE.ObjectSelector.setPinnedSelector(true);
		}
		else
		{
		    EYE.ObjectSelector.setPinnedSelector(false);
		}
    }

    function hideSelector()
    {
        setPinnedSelector(false);
        EYE.ObjectSelector.hide();
    }
    
    function doPinClicked(menu)
    {
         if (menu && menu.node)
         {
             if (isDud(menu.pinned))
            	 menu.pinned = false;
        	 
        	 menu.pinned = !menu.pinned;
        	 
        	 if (menu.pinned)
                 YAHOO.util.Dom.addClass(menu.node.firstChild.firstChild, "pinned");
        	 else
                 YAHOO.util.Dom.removeClass(menu.node.firstChild.firstChild, "pinned");
        	 
        	 setPinnedSelector(menu.pinned);
         }
    }

    function toggleConsolidation()
    {
      var newIsConsolidatedValue = EYE.ObjectSelector.toggleConsolidation();
      var browseControllsLink = document.getElementById("browseControllsLink");
      if (browseControllsLink)
        browseControllsLink.innerHTML = newIsConsolidatedValue ? "on" : "off";
    }

    Event.onDOMReady(function()
    {
        
    	var initialWidth = ${showTree ? 'EYE.ObjectSelector.DefaultWidth' : '0'};

        // check if we have any page info and if so override the iframe src we have written in the page and whether to show the tree
        var pageInfo = EYE.Util.getPageInfo();
        if (isDud(pageInfo) || ${param.url == null ? 'false' : 'true'})
        {
          // no page info, so set it
          var url = document.getElementById("displayFrame").src;
          EYE.Util.setPageInfo(url, ${showTree ? '1' : '0'});
        }
        else
        {
          // got page info, so use it to set current page
          var iFrame = document.getElementById("displayFrame");
          iFrame.src = pageInfo.url;
          if (pageInfo.tree == 1)
            initialWidth = EYE.ObjectSelector.DefaultWidth;
        }

        var layout = new YAHOO.widget.Layout({
            units: [
                { position: 'top', height: 51, body: 'topPanel' },
                { position: 'left', 
                  width: initialWidth, 
                  resize: true, 
                  body: 'leftPanel', 
                  header: "", 
                  collapse: true, 
                  close: false, 
                  collapseSize: 50,
                  scroll: false,
                  animate: false },
                { position: 'center', body: 'centerPanel' }
            ]
        });
        EYE.Globals.layout = layout;

        // Create Nav bar
        var buttonPanel = document.createElement("div");
        buttonPanel.className = "button-bar";
        var navPanel = createChild (buttonPanel, "div");
        var navbar = new EYE.NavBar(navPanel, true);
        navbar.addMenu ({text: "Browse", className: "tree-button", fn: doTreeClicked});
        navbar.addMenu ({text: "Drop Box", className: "drop-button", fn: doSelectionClicked});
        navbar.addMenu ({text: "", className: "pin-button", fn: doPinClicked, changeSelection: false, pinned: false});

        var browseControllsLink = document.getElementById ("browseControllsLink");
        if (browseControllsLink)
        {
            browseControllsLink.innerHTML = "${consolidateViews ? "on" : "off"}";
            browseControllsLink.onclick = toggleConsolidation;
        }
        // now add the control panel
        var header = document.getElementById ("leftHeader");
        if (header)
        {
            document.body.removeChild(header);
            buttonPanel.appendChild (header);
        }
        
        
        layout.on('render', function()
        {
            layout.getUnitByPosition('left').on('close', function() { closeLeft(); });
            // give the top unit a zindex to make it and it's menus go above the other units
            layout.getUnitByPosition('top').setStyle('zIndex', 10);

            var unit = layout.getUnitByPosition('left');
            if (unit && unit.header)
            {
                unit.header.innerHTML = "";
                unit.header.className = "button-bar";
                unit.header.appendChild (buttonPanel);
            }

            if (unit && unit._resize)
            {
            	var resizeKnob = unit._resize._handles['r'];
            	if (resizeKnob)
            	{
            	    if (resizeKnob.firstChild)
            	    	resizeKnob.firstChild.onclick = hideSelector; 
            	}
            }

        });

        EYE.Globals.userSelections = new EYE.UserSelections();
        EYE.Globals.userSelections.init("userSelectionDiv", navbar.getMenu(1).node);
        
        layout.on('resize', function()
        {
            var unit = EYE.Globals.layout.getUnitByPosition('left');
        	var width  = unit.get("width");
        	var height = unit.getSizes().body.h;
        	
            if (width && width < 50 )
            {
            	unit.set("width", initialWidth);
            	hideSelector();
            }

            EYE.Globals.userSelections.resize(width, height);
        });
        
        layout.render();

        navbar.selectMenu (0, true);
        
        EYE.Globals.features =
        {
          platform: '<c:out value="${platform}"/>',
          edition: '<c:out value="${edition}"/>',
          multiServer: ${multi_server_support ? 'true' : 'false'},
          ipv6: ${ipv6_support ? 'true' : 'false'}
        };
        updateHeaderInfo();
        var statusInfo = EYE.StatusInfo.instance(true);
        var statusInfoVisual = new EYE.StatusInfoVisual("warningCell", "toggleHeaderPaneButton", "statusPanel", statusInfo);

        var onMenuItemClick = function(p_oValue)
        {
            if( p_oValue == "singleChart")
            {
                openInFrame('/webUI/reportBuilder.do?type=singlechart');                
            }
            else if( p_oValue == "singleTable")
            {
                openInFrame('/webUI/reportBuilder.do?type=singletable');
            }
        }

        var reportBuilderButton = document.getElementById ("reportBuilderButton");

        if (reportBuilderButton)
        {
            var reportContextMenu = new EYE.ContextMenu(reportBuilderButton, new EYE.MenuSelectionProvider());
            var menuDef = {name:"--SHOWSINGLECHART--", displayName: "Single Chart", position:0, group:"-LOCAL-", actionArg:"singleChart"};
            menuDef.action = onMenuItemClick;
            reportContextMenu.addLocalMenu (menuDef);

            menuDef = {name:"--SHOWSINGLETABLE--", displayName: "Single Table", position:1, group:"-LOCAL-", actionArg:"singleTable"};
            menuDef.action = onMenuItemClick;
            reportContextMenu.addLocalMenu (menuDef);
        }
        
        var chartLink = document.getElementById("chartLink");
        if (chartLink)
        {
            var dataListHandler = function()
            {
                var list = EYE.Globals.userSelections.getSelectedSelections();
                if (!list || list.length === 0)
                    list = EYE.Globals.userSelections.getAllSelections();
                return list;
            };
            
            var itemTranslateHandler = function(item) {
                return {
                    serverId: item.serverId,
                    id: item.objectId,
                    assocName: item.assocName,
                    streamName: item.streamName,
                    chartObjName: item.objDesc,
                    parentName: (item.parent ? item.parent.displayName : null),
                    attr: [{
                        name: item.attrName
                    }]
                };
            };
            
            var chartHelper = new EYE.ObjectDetails.ChartActionHelper(true, dataListHandler, itemTranslateHandler);
            chartLink.onclick = chartHelper.gotoChartValidatingInput;
            isDebug() && debug("Set onclick event to element of id='chartLink'");
        }
        
        if (EYE.Globals.globalDragDrop)
        	EYE.Globals.globalDragDrop.enableDragDrop();
      });
  })();

   function onFrameLoad(frame)
   {
	   (function() {
		    // set the cookie here with the page url
		    //document.getElementById("displayFrame").src;
		    var frameDocument = EYE.IFrameHelper.getFrameDocument(frame);
	
		    if(frameDocument && frameDocument.location)
		    {
	            var url  = frameDocument.location.toString();
	            var path = frameDocument.location.pathname
	        	EYE.Util.setPageInfo(url, isShowTree(path) ? 1 : 0);
			}
		   EYE.IFrameHelper.onFrameLoad(frame);
	   })();
   }
 

   
    </script>

<STYLE>
#headerMessageDiv {
	color: #FFFFFF;
}

#headerInfoTable td {
	color: #FFFFFF;
}

#headerInfoTable .tdNoWrap {
	color: #FFFFFF;
}

a:link.header {
	color: #FFFFFF;
}

a:visited.header {
	color: #FFFFFF;
}

a:hover.header {
	color: #000000;
}

a:active.header {
	color: #111111;
}

.yui-skin-sam #topMenuBarWrap .yuimenubar {
	border: none !important;
}

.yui-skin-sam #topMenuBarWrap .yuimenubaritemlabel {
	border: none !important;
}

#topMenuBar {
	/* Make sure we give a very large width to prevent the menu from wrapping */
	width: 2000px;
}

#topMenuBarWrap {
	padding-bottom: 2px;
}

#searchBarWrap {
	position: relative;
	width: 100%;
	z-index: 99;
}

#searchBar {
	position: absolute;
	right: 0;
	top: 0;
	z-index: 99;
}

#searchBar #searchpattern {
	height: 18px;
}

#topMenuBarWrap,#searchBar {
	border: none;
	background: url(/webUI/yui/build/assets/skins/sam/sprite.png) repeat-x 0px 0px scroll transparent;
}

.tree-button .text {
	background: url(/webUI/images/eyeButtons.png) no-repeat 0px 2px;
}

.drop-button .text {
	background: url(/webUI/images/eyeButtons.png) no-repeat 0px -23px;
}

/**
    The top level menu putting extra space. There fore move the navbar by few pixils 
**/
.navbar {
	margin-top: 3px;
}

.pin-button .pinned .text {
	background: url(/webUI/images/eyeButtons.png) no-repeat 0px -50px !important;
}

.pin-button .text {
	background: url(/webUI/images/eyeButtons.png) no-repeat 0px -75px !important;
}

.pin-button .text {
	padding: 0px;
	padding-right: 2px !important;
	width: 17px;
	height: 16px;
	float: right !important;
	margin-top: 2px;
	margin-left: 0px;
	margin-right: 0px;
	margin-bottom: 2px;
}

.pin-button .text-wrap {
	padding-left: 0px;
	padding-right: 0px;
}

.yui-skin-sam .yui-layout-unit .yui-resize-handle-r .yui-layout-resize-knob
	{
	position: absolute;
	background: url(/webUI/images/prev.gif) no-repeat -4px 0px;
	top: 45%;
	left: 0;
	width: 6px;
	height: 15px;
	z-index: 5;
	cursor: pointer;
}

.yui-skin-sam .yui-layout-hd,.button-bar {
	overflow: hidden;
}

.button-bar {
	/*   background:  white url(/webUI/images/buttonBorder.png) repeat-x 0 31px ; */
	background-color: white;
}

.openLeftKnob {
	background: url(/webUI/images/next.gif) no-repeat -10px 0px;
	position: absolute;
	top: 50%;
	left: 0;
	width: 8px;
	height: 15px;
	z-index: 5;
	cursor: pointer;
}

.create-new-view-button {
	float: right;
	width: 18px;
	height: 18px;
	margin: 0px;
	cursor: pointer;
	background: url(/webUI/images/new_view.png) no-repeat 0px 0px;
}

.save-selection-button {
	background: url(/webUI/data/images/MapButtons.png) no-repeat 0px -50px;
}

.clear-selection-button {
	background: url(/webUI/data/images/MapButtons.png) no-repeat 0px 0px;
	margin-right: 15px !important;
}

.delete-selection-button {
	background: url(/webUI/data/images/MapButtons.png) no-repeat 0px -350px;
}

.open-selection-button {
	background: url(/webUI/data/images/MapButtons.png) no-repeat 0px -25px;
}

.report-builder-button {
	background: url(/webUI/images/report_builder.png) no-repeat 0 0;
	float: right !important;
}

.chart-button {
	background: url(/webUI/images/open_chart.png) no-repeat 0 0;
	float: right !important;
}

.selection-ctr-button {
	float: left;
	width: 18px;
	height: 18px;
	margin: 3px;
	cursor: pointer;
}

#userSelectionControlls { 
	/* border-top: gray solid 1px; */
	overflow: hidden;
	height: 21px;
	width: 100%;
	background: #F9F9F9;
	border-bottom: #f5f5f5 solid 1px;
}

#userSelectionDiv {
	height: 100%;
	width: 100%;
	background-color: white;
}

#browseControlls { 
	/* border-top: gray solid 1px; */
	background: #F9F9F9;
	height: 21px;
	overflow: hidden;
	border-bottom: #f5f5f5 solid 1px;
}

#browseControllsContent {
	font-family: tahoma, verdana, arial, helvetica, sans-serif;
	font-size: 8pt;
	font-weight: normal;
	color: #555555;
	text-align: left;
	margin: 3px;
}

#browseControlls a {
	font-weight: bold;
}
</STYLE>
</head>
<body class="yui-skin-sam">
	<div id="topPanel">
		<table class="bannerHeader" border='0' width='100%' height='30' cellspacing='0' cellpadding='0'>
			<tr>
				<td width=290px></td>
				<td align='right'>
					<div id='headerMessageDiv' class='heading' align='right'></div>
				</td>
				<td align='right'>
					<table id='headerInfoTable' border='0' cellspacing='0' cellpadding='0' style="margin-right: 5px">
					</table>
				</td>
			</tr>
		</table>
		<%@ include file="/WEB-INF/jsp/navigationMenu.jspf"%>
	</div>
	<div id="statusPanel">
		<div class="hd">Server Status</div>
		<div class="bd"></div>
		<div class="ft"></div>
	</div>

	<div id="leftPanel" style="width: 100%; height: 100%">
		<%@ include file="/WEB-INF/jsp/objectSelector.jspf"%>
	</div>

	<div id="centerPanel" style="width: 100%; height: 100%;">
		<iframe id="displayFrame" 
				name="displayFrame" 
				width="100%"
				height="100%" 
				frameborder="0" 
				scrolling="auto"
				src="<c:out value="${frameURL}"/>" 
				onload="onFrameLoad(this);">
		</iframe>
	</div>
	<!-- to allow auto discovery and candidate devices panels to be launched -->
	<div id="openLeftKnob" class="hidden_item openLeftKnob" onclick="EYE.ObjectSelector.show()"></div>
	<div id="autoDiscoveryPanel"></div>
	<div id="candidateDevicesPanel"></div>
	<div id="leftHeader">
		<div id="browseControlls" class="hidden_item">
			<div id="browseControllsContent">
				<div style="float: left;">
					Consolidate servers: <a id="browseControllsLink" href="javascript:;" onclick="toggleConsolidation()"></a>
				</div>
				<c:if test="${hasCreateViewsPermission}">
<!--					<div style="float: right;" title="Create New Top-Level View" onclick="EYE.ViewManagement.createView()"><a style="font-weight: normal;" href="#">New View</a></div>-->
					<div class="create-new-view-button" title="Create New Top-Level View" onclick="EYE.ViewManagement.createView()"></div>
				</c:if>
			</div>
		</div>
		<div id="userSelectionControlls" class="hidden_item">
			<div class="selection-ctr-button delete-selection-button" title="Delete" onclick="EYE.Globals.userSelections.deleteSelections()"></div>
			<div class="selection-ctr-button clear-selection-button" title="Clear" onclick="EYE.Globals.userSelections.clearSelections()"></div>
			<div class="selection-ctr-button save-selection-button" title="Save" onclick="EYE.Globals.userSelections.showSaveSelections()"></div>
			<div class="selection-ctr-button open-selection-button" title="Open" onclick="EYE.Globals.userSelections.showLoadSelections()"></div>
			<a class="${hasBuilderPermission ? '' : 'hidden_item'}" target="displayFrame" href="/webUI/reportBuilderList.do"> <div id="reportBuilderButton" class="selection-ctr-button report-builder-button" title="Report Builder"></div></a>
			<a id="chartLink" target="displayFrame"><div id="chartButton" class="selection-ctr-button chart-button" title="Show on Chart"></div></a>
		</div>
	</div>
</body>
</html>
